package com.pattern.design.designpattern.Compose;

import com.pattern.design.designpattern.MainActivity;

import java.util.ArrayList;
import java.util.List;

/**
 * author:harisucici on 2018/10/11 15:30
 * email:harisucici@gmail.com
 * name:
 * todo:
 */
public class CompositeBranch extends Component {
    private String name;
    private List<Component> list = new ArrayList<>(2);

    /**
     * Instantiates a new Composite branch.
     *
     * @param s the s
     */
    public CompositeBranch(String s) {
        super(s);
        this.name = s;
    }

    @Override
    public void doSth() {
        MainActivity.systemOut(name);
        if (list.size()!=0){
            for(Component component:list){
                component.doSth();
            }
        }
    }

    /**
     * Add child.
     *
     * @param child the child
     */
    public void addChild(Component child){
        list.add(child);
    }

    /**
     * Remove child.
     *
     * @param child the child
     */
    public void removeChild(Component child){
        list.remove(child);
    }

    /**
     * Get child.
     *
     * @param index the index
     */
    public void getChild(int index){
        list.get(index);
    }

}
